package com.example.boxuegu.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.boxuegu.R;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private FrameLayout mBodyLayout;
    public LinearLayout mBottomLayout;
    private View mCourseBtn,mExercisesBtn,mMyInfoBtn;
    private TextView tv_course,tv_exercises,tv_myInfo,tv_back,tv_main_title;
          private ImageView iv_course,iv_exercises,iv_myInfo;
    private RelativeLayout rl_title_bar;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        initBodyLayout();
        initBottomBar();
        setInitStatus();
    }

    private void setInitStatus() {
        createView(0);
    }





    private void init() {
        tv_back=findViewById(R.id.tv_back);
        tv_main_title=findViewById(R.id.tv_main_title);
        tv_main_title.setText("博学谷课程");
        rl_title_bar=findViewById(R.id.title_bar);
        rl_title_bar.setBackgroundColor(Color.parseColor("#30B4FF"));
        tv_back.setVisibility(View.GONE);
        initBodyLayout();
    }

    private void initBottomBar() {
        mBottomLayout=findViewById(R.id.main_bottom_bor);
        mCourseBtn=findViewById(R.id.bottom_bar_course_btn);
        mExercisesBtn=findViewById(R.id.bottom_bar_exercises_btn);
        mMyInfoBtn=findViewById(R.id.bottom_bar_image_myinfo);
        tv_course=findViewById(R.id.bottom_bar_text_course);
        tv_exercises=findViewById(R.id.bottom_bar_text_exercises);
        tv_myInfo=findViewById(R.id.bottom_bar_text_myinfo);
        iv_course=findViewById(R.id.bottom_bar_image_course);
        iv_exercises=findViewById(R.id.bottom_bar_image_exercises);
        iv_myInfo=findViewById(R.id.bottom_bar_image_myinfo);

    }

    private void initBodyLayout() {
        mBodyLayout=findViewById(R.id.main_body);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bottom_bar_course_btn:
                clearBottomImageState();
                selectDisplayView(0);
                break;
        }
    }

    private void clearBottomImageState() {
    }

    private void selectDisplayView(int index) {
        createView(index);
    }
    private void createView(int index) {
        switch (index){
            case 0:
                Toast.makeText(this, "课程界面创建", Toast.LENGTH_SHORT).show();
                break;
        }
    }
    long exitTime;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_BACK){
            if(System.currentTimeMillis()-exitTime>2000){
                Toast.makeText(this, "再按一次推出博学谷", Toast.LENGTH_SHORT).show();
                exitTime=System.currentTimeMillis();
            }else {
                MainActivity.this.finish();
                System.exit(0);

            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}